<template>
  <a-modal
    :title="$t('新增')"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    :okText="$t('确定')"
    @cancel="handleCancel"
    :cancelText="$t('取消')"
    v-drag
  >
    <a-spin :spinning="confirmLoading">
      <a-form-model :model="dataForm" ref="form" :rules="rules">
        <a-row>
          <a-col :span="24">
            <a-form-model-item :label="$t('项目名称')" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="gameId">
              <a-select
                v-model="dataForm.gameId"
                show-search
                :placeholder="$t('请输入项目编码/名称')"
                :filter-option="false"
                :not-found-content="null"
                option-label-prop="label"
                @search="handleGoodsSearch"
              >
                <a-select-option :label="good.name" v-for="good in addGameList" :key="good.id">{{
                  good.code+"-"+good.name
                }}</a-select-option>
              </a-select>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </a-spin>
  </a-modal>
</template>

<script>
import { postAction, httpAction } from '@/api/manage'
import pick from 'lodash.pick'
import { getAction, putAction } from '../../../api/manage'

export default {
  name: 'AddGameModal',
  data() {
    return {
      width: 600,
      visible: false,
      dataForm: {
        gameId: ''
      },
      confirmLoading: false,
      labelCol: {
        xs: { span: 24 },
        sm: { span: 4 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      rules: {
        gameId: [{ required: true, message: this.$t('请选择项目') }],
      },
      addGameList: [],
    }
  },
  methods: {
    add() {
      this.visible = true
      this.dataForm = {}
      this.getGameList()
    },
    handleGoodsSearch(value) {
      this.getGameList(value)
    },
    getGameList(value) {
      let that = this
      let querydata = {}
      querydata.pageNo = 1
      querydata.pageSize = 10
      querydata.gameInfo = value
      getAction('/game/bisGame/list', querydata).then((res) => {
        if (res.success) {
          that.addGameList = res.result.records
        }
      })
    },
    handleOk() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          console.log(this.dataForm)
          this.$emit('ok', this.dataForm)
          this.close()
        }
      })
    },
    handleCancel() {
      this.close()
    },
    close() {
      this.visible = false
    },
  },
}
</script>
<style>
.batchForm .ant-form-item-label {
  width: 30%;
}
.batchForm .ant-form-item-control-wrapper {
  width: 62.5%;
}
</style>